package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.dubbo.api.db.MessageApi;
import com.tanhua.dubbo.api.mapper.AnnouncementMapper;
import com.tanhua.model.db.Announcement;
import com.tanhua.model.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class MessageApiImpl implements MessageApi {

    @Autowired
    private AnnouncementMapper announcementMapper;

    /**
     *      获取公告
     * @param page
     * @param pagesize
     * @return
     */
    @Override
    public PageResult<Announcement> getAnnouncement(Long page, Long pagesize) {
        Page<Announcement> pages = new Page<>(page, pagesize);
        LambdaQueryWrapper<Announcement> qw = new LambdaQueryWrapper<>();
        qw.orderByAsc(Announcement::getId);
        Integer integer = announcementMapper.selectCount(qw);
        Page<Announcement> selectPage = announcementMapper.selectPage(pages, qw);
        return new PageResult<Announcement>(page,pagesize,integer.longValue(),selectPage.getRecords());
    }
}
